//注册
<template>
  <div>

  </div>
</template>

<script>
//  import Loading from '../components/Loading.vue'
  export default {
    name: 'register',
    data() {
      return {
        ruleForm: {
          username: '',
          password: ''
        },
        rules: {
          username: [
            {required: true, message: '傻逼，你账号填了吗？', trigger: 'blur'},
            {min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '傻逼，你密码填了吗？', trigger: 'blur'},
            {min: 6, max: 10, message: '长度在 6 到 10 个字符', trigger: 'blur'}
          ]
        }
      }
    },
    components: {},
    methods: {
      //登录请求
      register() {
        //这里例子用的哈希算法来自./js/sha1.min.js
//        let password_sha = hex_sha1(hex_sha1(this.password));
        //请求后端
        this.ajax.post('/api/register', {
          username: this.ruleForm.username,
          password: this.ruleForm.password
        }).then((data) => {
          console.log(data);
          if (data.status===200 && data.data.code===0) {
            this.$message({message: '用户名重复', type: 'error'});
          }else if(data.status===200 && data.data.code===1){
            this.$router.push('/login');
            this.$message({message: '注册完成', type: 'success'});
          }
        }, (err) => {
          console.log(err);
          this.$message({message: '注册失败', type: 'error'});
        });

        /*//演示用
        setTimeout(() => {
          //登录状态15天后过期
          let expireDays = 1000 * 60 * 60 * 24 * 15;
          this.setCookie('session', 'blablablablabla...', expireDays);
          this.isLoging = false;
          //登录成功后
          this.$router.push('/user-info');
          this.$message({message: '已登录', type: 'success'});
        }, 1000);*/
      },
      submitLogin(form) {
        this.$refs[form].validate((val) => {
          if (val) {
            this.register();
          }
        })
      }
    },
    mounted(){

    },
    updated(){
      /*this.$refs.ruleForm.resetFields();
      this.$refs.ruleForm.clearValidate();*/
    }
  }
</script>

<style lang="less" scoped>
  @import "../assets/css/login";
</style>
